package com.yuyu.sequence.seq;

public class SeqConstant {

    /**
     * 序列枚举
     */
    public enum SeqEnum {

        ORDER_ID(1, SeqTypeEnum.INCREASE.getType(), "sales/seq/orderid", 1000, 1000, 100, 100, false, "中台销售订单ID");

        /**
         * id
         */
        private int id;

        /**
         * 类型
         */
        private int type;

        /**
         * redis key
         */
        private String redisKey;

        /**
         * 初始起始值
         */
        private long initStart;

        /**
         * 同步数据库步长
         */
        private long syncDbStep;

        /**
         * 客户端每次获取步长
         */
        private long clientFetchStep;

        /**
         * 客户端队列大小
         */
        private int clientQueueSize;

        /**
         * 是否有序
         */
        private boolean isOrder;

        /**
         * 描述
         */
        private String desc;


        SeqEnum(int id, int type, String redisKey, long initStart, long syncDbStep, long clientFetchStep, int clientQueueSize, boolean isOrder, String desc) {
            this.id = id;
            this.type = type;
            this.redisKey = redisKey;
            this.initStart = initStart;
            this.syncDbStep = syncDbStep;
            this.clientFetchStep = clientFetchStep;
            this.clientQueueSize = clientQueueSize;
            this.isOrder = isOrder;
            this.desc = desc;
        }

        public int getId() {
            return id;
        }

        public int getType() {
            return type;
        }

        public long getInitStart() {
            return initStart;
        }

        public long getSyncDbStep() {
            return syncDbStep;
        }

        public long getClientFetchStep() {
            return clientFetchStep;
        }

        public int getClientQueueSize() {
            return clientQueueSize;
        }

        public String getRedisKey() {
            return redisKey;
        }

        public boolean isOrder() {
            return isOrder;
        }

        public String getDesc() {
            return desc;
        }

        public static SeqConstant.SeqEnum getSeqEnum(int id) {
            for (SeqConstant.SeqEnum seqEnum : SeqConstant.SeqEnum.values()) {
                if (id == seqEnum.getId()) {
                    return seqEnum;
                }
            }
            return null;
        }
    }


    /**
     * 类型
     */
    public enum SeqTypeEnum {

        INCREASE(1, "递增", null),
        RESET_EVERY_DAY(2, "每天0点重置", "0 0 0 * * ?"),
        RESET_EVERY_MONTH(3, "每月1号0点重置", "0 0 0 1 * ?");

        /**
         * 类型
         */
        private int type;
        /**
         * 名称
         */
        private String name;

        /**
         * cron表达式
         */
        private String cron;

        SeqTypeEnum(int type, String name, String cron) {
            this.type = type;
            this.name = name;
            this.cron = cron;
        }

        public int getType() {
            return type;
        }

        public String getName() {
            return name;
        }

        public String getCron() {
            return cron;
        }

        public static SeqConstant.SeqTypeEnum getSeqTypeEnum(int type) {
            for (SeqConstant.SeqTypeEnum typeEnum : SeqConstant.SeqTypeEnum.values()) {
                if (type == typeEnum.getType()) {
                    return typeEnum;
                }
            }
            return null;
        }
    }
}
